package cn.imvc.app.controllers.info;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;

import cn.imvc.app.controllers.goods.GoodsControllerImpl;
import cn.imvc.app.entities.Article;
import cn.imvc.app.entities.ArticleClass;
import cn.imvc.app.models.ArticleClassModel;
import cn.imvc.app.models.ArticleModel;
import cn.imvc.app.models.LoggingModel;
import cn.imvc.core.DialogBean;
import cn.imvc.core.Render;
import cn.imvc.data.domain.ViewRequest;
/**
 * 
 * @author wjx
 * @time 2016年7月15日 下午5:06:23 
 *
 */
public class ArticleClassControllerImpl implements ArticleClassController {
	static Logger logger = Logger.getLogger(ArticleClassControllerImpl.class);
	public Page<ArticleClass> page;
	public ArticleClass articleClass;
	public String articleClassTree;
	public ViewRequest viewRequest;
	public int id;
	public int classId;
	private int article_id;
	public int[] ids;
	//文章类型
	private String articleClasses;
	@Autowired
	ArticleClassModel articleClassModel;
	@Autowired
	LoggingModel loggingModel;
	public String index() {
		articleClasses = articleClassModel.getArticleClasses();
		return "articleClass/index";
	}
	public String show() {
		return "articleClass/show";
	}
	
	public String detail(){
		articleClass = articleClassModel.get(id);
		return "articleClass/show";
	}
	
	public String editNew() {
		articleClass = articleClassModel.get(id);
		return "articleClass/editNew";
	}

	public String create() {
		articleClassModel.save(id,articleClass);
		return Render.json(new DialogBean("200", "创建成功","article-class", "closeCurrent"));
	}

	public String edit() {
		if(id == 0){
			return Render.json(new DialogBean("300", "没有所需要的内容！","article-class", "closeCurrent"));
		}
		articleClass=articleClassModel.get(id);
		return "articleClass/edit";
	}

	public String update() {
		articleClassModel.update(articleClass,id);
		return Render.json(new DialogBean("200", "修改成功","article-class"));
	}

	public String destroy() {
		if(id == 0){
			return Render.json(new DialogBean("300", "没有所删除的内容！","article-class", "closeCurrent"));
		}
		String result = articleClassModel.delete(id);
		if(result.equals("")){
			return Render.json(new DialogBean("200", "删除成功","article-class"));
		}else{
			return Render.json(new DialogBean("300", result,"article-class")); 
		}
	}

	public String destroyBatch() {
		return null;
	}
	/**
	 * 外部调用
	 * @return
	 */
	public String showAll() {
		articleClassTree = articleClassModel.treeLookup();
		return "articleClass/showAll";
	}
	
	public String getArticleClassTree() {
		return articleClassTree;
	}


	public void setArticleClassTree(String articleClassTree) {
		this.articleClassTree = articleClassTree;
	}


	public int getArticle_id() {
		return article_id;
	}


	public void setArticle_id(int article_id) {
		this.article_id = article_id;
	}
	public void setViewRequest(ViewRequest viewRequest) {
		this.viewRequest = viewRequest;
	}

	
	public ArticleClass getArticleClass() {
		return articleClass;
	}


	public void setArticleClass(ArticleClass articleClass) {
		this.articleClass = articleClass;
	}


	public void setId(int id) {
		this.id = id;
	}

	public void setIds(int[] ids) {
		this.ids = ids;
	}
	
	public void setClassId(int classId) {
		this.classId = classId;
	}
	
	public String search() {
		return null;
	}
	
	public String getArticleClasses() {
		return articleClasses;
	}


	public void setArticleClasses(String articleClasses) {
		this.articleClasses = articleClasses;
	}

	
}
